/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package aptech.semester.code.gui;

import aptech.semester.code.conn.MyLib;
import java.sql.*;
import java.util.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author vi
 */
public class Education extends javax.swing.JInternalFrame {
    TbEduList bList;
    
    public Education(JFrame mainFrame) {
        initComponents();
        initControl();
        bList = new TbEduList();
        btnChange.setEnabled(false);
        btnSave.setEnabled(false);
        btnDel.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtEduLevel = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtDes = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        btnExit = new javax.swing.JButton();
        btnDel = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        btnReset = new javax.swing.JButton();
        btnChange = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        EducationTable = new javax.swing.JTable();

        setClosable(true);
        setTitle("Education");
        setPreferredSize(new java.awt.Dimension(800, 600));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Details"));

        jLabel1.setText("Education Level");

        txtEduLevel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtEduLevelActionPerformed(evt);
            }
        });

        jLabel3.setText("Description");

        txtDes.setColumns(20);
        txtDes.setRows(5);
        jScrollPane2.setViewportView(txtDes);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtEduLevel, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 396, Short.MAX_VALUE))
                    .addComponent(jScrollPane2))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtEduLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Command"));

        btnExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/exit.png"))); // NOI18N
        btnExit.setText("Exit");
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        btnDel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/btn_cancel.png"))); // NOI18N
        btnDel.setText("Delete");
        btnDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelActionPerformed(evt);
            }
        });

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/add.png"))); // NOI18N
        btnAdd.setText("Add New");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        btnReset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/btn_reset.png"))); // NOI18N
        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });

        btnChange.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/Update.png"))); // NOI18N
        btnChange.setText("Change");
        btnChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChangeActionPerformed(evt);
            }
        });

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/report.png"))); // NOI18N
        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(200, Short.MAX_VALUE)
                .addComponent(btnAdd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnChange)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnReset)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnExit)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnExit)
                .addComponent(btnDel)
                .addComponent(btnAdd)
                .addComponent(btnReset)
                .addComponent(btnChange)
                .addComponent(btnSave))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("List Education"));

        jScrollPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jScrollPane1MousePressed(evt);
            }
        });

        EducationTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Education Level", "Description"
            }
        ));
        EducationTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                EducationTableMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(EducationTable);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 779, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 264, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtEduLevelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtEduLevelActionPerformed
        String Edu = txtEduLevel.getText().trim();
        TbEdu b = bList.search(Edu);           
               
        if(b == null) {
            btnChange.setEnabled(false);
            btnDel.setEnabled(false);
            btnReset.setEnabled(true);
            btnSave.setEnabled(false);
            
            btnAdd.setEnabled(true);
            txtEduLevel.setEnabled(true);
            txtDes.setEnabled(true);
        } else {
            btnChange.setEnabled(true);
            btnDel.setEnabled(true);
            btnReset.setEnabled(true);         
            btnAdd.setEnabled(true);
            txtEduLevel.setEnabled(true);
            txtDes.setEnabled(true);
            
            txtEduLevel.setText(b.Education);
            txtDes.setText(b.Description);               
        }
    }//GEN-LAST:event_txtEduLevelActionPerformed

    private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelActionPerformed
        int r = EducationTable.getSelectedRow();
        int id = Integer.parseInt(EducationTable.getValueAt(r, 0).toString());
                
        if(bList.delete(id)==true) {
            JOptionPane.showMessageDialog(null, "Delete successful !");
            model.removeRow(r);
        } else {
            JOptionPane.showMessageDialog(null, "Delete failed !");
        }    
            //tat 3 nut insert,update,delete
            btnAdd.setEnabled(false);
            btnChange.setEnabled(false);
            btnDel.setEnabled(false);
            
            //mo nut reset
            btnReset.setEnabled(true);
        
            //mo textbox Education
            txtEduLevel.setEnabled(true);
            
            //tat cac textbox con lai
            txtDes.setEnabled(false);
            
            txtEduLevel.setText(null);
            txtDes.setText(null);
    }//GEN-LAST:event_btnDelActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        txtEduLevel.setEditable(true);
        txtDes.setEditable(true);
        
        String Education = txtEduLevel.getText().trim();
        String Description = txtDes.getText().trim();
        
        if (Education.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Education cannot Blank!");
            txtEduLevel.requestFocus();
            return;
        }
        
        if (Description.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Description cannot Blank!");
            txtDes.requestFocus();
            return;
        }
        TbEdu b = new TbEdu();
        b.Education = txtEduLevel.getText().trim();
        b.Description = txtDes.getText().trim();
        
        if(bList.insert(b)==true) {
            JOptionPane.showMessageDialog(null,"Insert successful !");
            model = (DefaultTableModel) EducationTable.getModel();
            model.setRowCount(0);
            for (TbEdu item : bList.getList()) {
                model.addRow(item.toVector());
            }
        } else {
            JOptionPane.showMessageDialog(null, "Insert failed !");
        }
            btnAdd.setEnabled(true);
            btnChange.setEnabled(true);
            btnDel.setEnabled(true);
            btnReset.setEnabled(true);
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChangeActionPerformed
            btnSave.setEnabled(true);
        
            btnAdd.setEnabled(false);
            btnChange.setEnabled(false);
            btnDel.setEnabled(false);
            
            //mo nut reset
            btnReset.setEnabled(true);
        
            //mo textbox Education
            txtEduLevel.setEnabled(true);
            
            //tat cac textbox con lai
            txtDes.setEnabled(true);
    }//GEN-LAST:event_btnChangeActionPerformed

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed
        txtEduLevel.setText(null);
        txtDes.setText(null);
        
        btnAdd.setEnabled(true);
    }//GEN-LAST:event_btnResetActionPerformed

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
        int r = JOptionPane.showConfirmDialog(null, "Are you sure to exit ?", "Warning", JOptionPane.OK_CANCEL_OPTION);
            if (r == JOptionPane.OK_OPTION) {
                this.dispose();
            }
    }//GEN-LAST:event_btnExitActionPerformed

    private void jScrollPane1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane1MousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jScrollPane1MousePressed

    private void EducationTableMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_EducationTableMousePressed
        btnAdd.setEnabled(false);
        btnSave.setEnabled(false);
        btnChange.setEnabled(true);
        btnDel.setEnabled(true);
        
        txtEduLevel.setEnabled(false);
        txtDes.setEnabled(false);
        int r = EducationTable.getSelectedRow();
        
        txtEduLevel.setText(EducationTable.getValueAt(r, 1).toString());
        txtDes.setText(EducationTable.getValueAt(r, 2).toString());
    }//GEN-LAST:event_EducationTableMousePressed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        String Education = txtEduLevel.getText().trim();
        String Description = txtDes.getText().trim();
        
        if (Education.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Education cannot Blank!");
            txtEduLevel.requestFocus();
            return;
        }
        
        if (Description.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Description cannot Blank!");
            txtDes.requestFocus();
            return;
        }
        TbEdu b = new TbEdu();
        b.Education = txtEduLevel.getText().trim();
        b.Description = txtDes.getText().trim();
        int r = EducationTable.getSelectedRow();
        int id = Integer.parseInt(EducationTable.getValueAt(r, 0).toString());
        b.ID = id;
        
        if(bList.update(b)==true) {
            JOptionPane.showMessageDialog(null,"Change successful !");
            model.removeRow(r);
            model.addRow(b.toVector());
        } else {
            JOptionPane.showMessageDialog(null, "Change failed !");
        }    
            //tat 3 nut insert,update,delete
            btnAdd.setEnabled(false);
            btnChange.setEnabled(false);
            btnDel.setEnabled(false);
            
            //mo nut reset
            btnReset.setEnabled(true);
        
            //mo textbox Education
            txtEduLevel.setEnabled(true);
            
            //tat cac textbox con lai
            txtDes.setEnabled(false);
            
            txtEduLevel.setText(null);
            txtDes.setText(null);
    }//GEN-LAST:event_btnSaveActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable EducationTable;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnChange;
    private javax.swing.JButton btnDel;
    private javax.swing.JButton btnExit;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnSave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea txtDes;
    private javax.swing.JTextField txtEduLevel;
    // End of variables declaration//GEN-END:variables
    DefaultTableModel model; 
    TableRowSorter<TableModel> sorter;
    private void initControl() {
        // 1. Fill du lieu vo comboboxn Standard ID
        TbEduList o1 = new TbEduList();
        for (TbEdu item : o1.getList()) {
        }
       
        model = (DefaultTableModel) EducationTable.getModel();
        sorter = (TableRowSorter<TableModel>) EducationTable.getRowSorter();
        
        TbEduList o2 = new TbEduList();
        for (TbEdu item : o2.getList()) {
            model.addRow(item.toVector());
        }
      
    }
    
    public class TbEdu {

        public String Education, Description;
        public int ID;

        public TbEdu() {
        }

        public TbEdu(String Education, String Description, int ID) {
            this.Education = Education;
            this.Description = Description;
            this.ID = ID;
        }

        public Vector toVector() {
            Vector v = new Vector();
            v.add(ID);
            v.add(Education);
            v.add(Description);
            return v;
        }
    }
    
    public class TbEduList {

        //tra ve danh sach cac doi tuonog nguoi dung trong bang tbBatch cua db
        public ArrayList<TbEdu> getList() {
            //tra ve 1 danh sach cac doi tuong nguoi dung trong bang Tbuser cua database
            ArrayList<TbEdu> ds = new ArrayList<>();

            try {
                //1.tao 1 ket noi
                Connection cn = MyLib.getCN();
                if (cn != null) {
                    //2. tao doi tuong statement chua lenh select sql
                    Statement st = cn.createStatement();

                    //3.cho thi hanh lenh truy van tren doi tuong nay va ket qua se dc tra ve doi tuong resulltset
                    ResultSet rs = st.executeQuery("select * from EDUCATION_LEVEL");

                    //4. duyuet ket qua tra ve trong resultset rs va fill vao arraylist ds.
                    while (rs.next()) {
                        TbEdu u = new TbEdu();
                        u.ID = rs.getInt(1);
                        u.Education = rs.getString(2);
                        u.Description = rs.getString(3);

                        ds.add(u);
                    }
                    rs.close();
                    cn.close();
                }
            } catch (Exception e) {

            }
            return ds;
        }

        //them du lieu vao database,chen 1 doi tuong lop hoc vao ben trong co so du lieu
        public boolean insert(TbEdu u) {

            try {
                //1. tao ket noi
                Connection cn = MyLib.getCN();

                //2.tao doi tuong lenh insert sql
                String sql = "insert EDUCATION_LEVEL values(?,?)";
                PreparedStatement pst = cn.prepareStatement(sql);              
                pst.setString(1, u.Education);
                pst.setString(2, u.Description);

                //3.cho thi hanh cau lenh sql
                int r = pst.executeUpdate();
                pst.close();       
                cn.close();
                return (r > 0);

            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }

        }

        public boolean update(TbEdu u) {

            try {
                //1. tao ket noi
                Connection cn = MyLib.getCN();

                //2.tao doi tuong lenh insert sql
                String sql = "update EDUCATION_LEVEL set EDUCATION_LEVEL_NAME = ?, DESCRIPTION = ? where ID = ?";
                PreparedStatement pst = cn.prepareStatement(sql);
                pst.setString(1, u.Education);
                pst.setString(2, u.Description);
                pst.setInt(3, u.ID);

                //3.cho thi hanh cau lenh sql
                int r = pst.executeUpdate();
                pst.close();
                cn.close();
                return (r > 0);

            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }

        }

        public boolean delete(int id) {

            try {
                //1. tao ket noi
                Connection cn = MyLib.getCN();

                //2.tao doi tuong lenh insert sql
                String sql = "delete from EDUCATION_LEVEL where ID = ?";
                PreparedStatement pst = cn.prepareStatement(sql);

                pst.setInt(1, id);

                //3.cho thi hanh cau lenh sql
                int r = pst.executeUpdate();
                pst.close();
                cn.close();
                return (r > 0);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Can not delete because of having employee belong to this education!");
                return false;
            }

        }
        
        public TbEdu search(String Edu) {
            TbEdu b = null;

            ArrayList<TbEdu> ds = new ArrayList<>();

            try {
                //1.tao 1 ket noi
                Connection cn = MyLib.getCN();

                //2. tao doi tuong statement chua lenh select sql
                String sql = ("select * from EDUCATION_LEVEL where EDUCATION_LEVEL_NAME like ?");
                PreparedStatement pst = cn.prepareStatement(sql);

                pst.setString(1, Edu);
                //3.cho thi hanh lenh truy van tren doi tuong nay va ket qua se dc tra ve doi tuong resulltset
                ResultSet r = pst.executeQuery();

                //4. duyuet ket qua tra ve trong resultset rs va fill vao arraylist ds.
                if (r.next()) {
                    b = new TbEdu();
                    b.ID = r.getInt(1);
                    b.Education = r.getString(2);
                    b.Description = r.getString(3);
                }
                pst.close();
                cn.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return b;
        }
    }
}
    
    

